/*
 * ITBConnection.java
 *
 * Created on 21. Juni 2007, 09:20
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.googlecode.oskis.library.db;
import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;

/**
 *
 * @author root
 */
public class OracleConnection  extends DBConnection {
    
    protected Connection createConnection() {
        Connection c;
        if (user==null || passwd==null || ip==null
            || port==null || database==null) {
            return(null);
        }
        try {
            OracleDataSource ods = new OracleDataSource();
            url="jdbc:oracle:thin:@"+ip+":"+port+":"+database;
            ods.setUser(user);
            ods.setPassword(passwd);
            ods.setURL(url);
            c=ods.getConnection();
            connected=true;
        } catch (SQLException e) {
            System.err.println(e);
            c=null;
            connected=false;
            connectionError=e.toString();
        }
        return(c);
    }
    
    
    
    
    /** Creates a new instance of ITBConnection 
     without Arguments connect as Sysadm to demodb Sulzbach*/
    public OracleConnection() {
        readProperties();
        this.db=createConnection();
    }
    
    public OracleConnection (String database) {
        readProperties();
        setDatabase(database);
        this.db=createConnection();
    }
    public OracleConnection(String ip,String database,String user,String passwd) {
        setDatabase(database);
        setIP(ip);
        setUser(user);
        setPasswd(passwd);
        this.db=createConnection();
    }
    
}
